package com.atguigu.spring.controller;

import jakarta.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller
@RequestMapping("/demo02")
public class Demo02ControllerMapping {

    @ResponseBody
    @RequestMapping("/ambiguous")
    public String ambiguousTest() {
        return "ok";
    }

    @ResponseBody
    @RequestMapping("/one/b?g")
    public String testOneCharacterMapping(HttpServletRequest request) {
        return "ok " + request.getServletPath();
    }

    @ResponseBody
    @RequestMapping("/star/*")
    public String testStarOne(HttpServletRequest request) {
        return "ok " + request.getServletPath();
    }

    @ResponseBody
    @RequestMapping("/two/star/**")
    public String testStarTwo(HttpServletRequest request) {
        return "ok " + request.getServletPath();
    }

    @ResponseBody
    @RequestMapping("/suffix/*.html")
    public String testHTMLSuffix(HttpServletRequest request) {
        return "ok " + request.getServletPath();
    }

    @ResponseBody
    @RequestMapping("/path/variable/{name}")
    public String testPathVariable(HttpServletRequest request) {
        return "ok " + request.getServletPath();
    }

    @ResponseBody
    @RequestMapping(value = "/test/method", method = RequestMethod.GET)
    public String testMethodMappingGet(HttpServletRequest request) {
        return "ok " + request.getMethod();
    }

    @ResponseBody
    @RequestMapping(value = "/test/method", method = RequestMethod.POST)
    public String testMethodMappingPost(HttpServletRequest request) {
        return "ok " + request.getMethod();
    }

    @ResponseBody
    @RequestMapping(value = "/test/multi/method", method = {RequestMethod.GET, RequestMethod.POST})
    public String testMethodMappingMulti(HttpServletRequest request) {
        return "ok " + request.getMethod();
    }

    @ResponseBody
    @GetMapping("/test/get/mapping")
    public String testGetMapping(HttpServletRequest request) {
        return "ok " + request.getMethod();
    }

    @ResponseBody
    @PostMapping("/test/post/mapping")
    public String testPostMapping(HttpServletRequest request) {
        return "ok " + request.getMethod();
    }

    @ResponseBody
    @PutMapping("/test/put/mapping")
    public String testPutMapping(HttpServletRequest request) {
        return "ok " + request.getMethod();
    }

    @ResponseBody
    @DeleteMapping("/test/delete/mapping")
    public String testDeleteMapping(HttpServletRequest request) {
        return "ok " + request.getMethod();
    }

    @ResponseBody
    @PostMapping(value = "/test/content/type", consumes = "application/json", produces = "application/json")
    public String testContentTypeMapping() {
        return "ok consumes produces";
    }
}
